<?php 
include_once('CLASS/autoload.php');
require_once ('CLASS/MyPDO.php');
require_once 'CLASS/Article/PreparationREQArticle.php';
$PrepREQ = new PreparationREQArticle(new MyPDO());
$page = new page_admin('news');
$page->URL(__FILE__);
$tbody="";
$page->titre = 'News';
$page->logo = 'newspaper-o';
//print_r($PrepREQ->SelectAll());
foreach ($PrepREQ->SelectAll() as $v1)
{
$select="";
	foreach ($PrepREQ->SelectAllRubrique() as $v2)
	{
		if ($v1['RUB_ID'] == $v2['RUB_ID'])
		{$select = $select.'<option value='.$v2['RUB_ID'].' selected>'.$v2['RUB_LIBELLE'].'</option>';}
		else
		{$select = $select.'<option value='.$v2['RUB_ID'].'>'.$v2['RUB_LIBELLE'].'</option>';}
	}	
	if(($v1['ART_DATEDEBVALID'] > date('Y-m-d, H:i:s')) && ($v1['ART_DATEFINVALID'] < date('Y-m-d, H:i:s')) || ($v1['ART_DATEFINVALID'])==NULL ){$afficher = '<span class="label label-success">OUI</span>'; } else {$afficher = '<span class="label label label-danger">NON</span>';}
$tbody = $tbody.'<tr id="'.$v1['ART_ID'].'">
			<td id="titrearticle" class="centered">'.utf8_encode($v1['ART_TITRE']).'</td>
       		<td id="contenuarticle" class="centered">'.utf8_encode(str_replace("<br><br>", "<br>",substr($v1['ART_CONTENU'],0,100))).'</td>
       		<td class="centered">'.$afficher.'</td>
       		<td id="datedebut" class="centered">'.($v1['ART_DATEDEBVALID'] ? date('d-m-Y', strtotime($v1['ART_DATEDEBVALID'])): '').'</td>
       		<td id="datefin" class="centered">'.($v1['ART_DATEFINVALID'] ? date('d-m-Y', strtotime($v1['ART_DATEFINVALID'])): '').'</td>
       		<td>
       				<select id="rubriquearticle" class="form-control" style="padding:inherit;">
						'.utf8_encode($select).'		
					</select>
       		</td>
      		<td class="centered"><a href="modifierarticle.php?article='.$v1['ART_ID'].'"><button class="btn btn-primary btn-default" name="modifier" type="submit"><i class="fa fa-pencil"></i></button></a></td>
      		<td class="centered"><a href="javascript:supprimer('.$v1['ART_ID'].')"><button class="btn btn-danger btn-default" id="supprimer"><i class="fa fa-trash-o "></td>
      		<td class="centered"><button type="button" class="btn btn-default"><i class="fa fa-envelope-o"></i></button></td>

          </tr>';
}
$page->contenu = '<script src="CLASS/Article/tableaunews.js"></script>
		<div class="col-lg-12">
                      <div class="content-panel">
					<a href="newarticle.php"><button style="margin-right:10px;" type="button" class="btn btn-round btn-success pull-right"><i class="fa fa-plus-square"></i> Nouveau</button></a>
                      <h4><i class="fa fa-newspaper-o"></i> Les Articles</h4>
                          <section id="unseen">
                            <table class="table table-bordered table-striped table-condensed">
                              <thead>
                              <tr>
                                <th class="centered"><i class="fa fa-sort-alpha-desc"></i> Titre</th>
                                <th class="centered"><i class="fa fa-inbox"></i> Contenu</th>
								<th class="centered"><i class=" fa fa-edit"></i> Afficher</th>
                                <th class="centered"><i class="fa fa-calendar"></i> Début Publication</th>
                                <th class="centered"><i class="fa fa-calendar"></i> Fin Publication</th>
                                <th class="centered"><i class="fa fa-folder"></i> Rubrique</th>
                              </tr>
                              </thead>
                              <tbody>'.$tbody.'
                              </tbody>
                          </table>
                          </section>
                  </div><!-- /content-panel -->
               </div>';
                             
$page->affiche();